<?php

function model_create_works($bdd, $name, $description, $id, $id_region,$type_img) {
if ($type_img != 3) {  
    $req = $bdd->prepare('INSERT INTO works(work_name, work_description,user_id,id_region,img_type) 
        VALUES(:name, :description, :user_id,:id_region,:img_type)');
    $req->execute(array(
        'name' => $name,
        'description' => $description,
        'user_id' => $id,
        'id_region' => $id_region,
        'img_type' => $type_img
    ));
}else{
    
     $req = $bdd->prepare('INSERT INTO works(work_name,  work_description,user_id,id_region) 
        VALUES(:name, :description, :user_id,:id_region,)');
    $req->execute(array(
        'name' => $name,
        'description' => $description,
        'user_id' => $id,
        'id_region' => $id_region
    ));
}}

function model_create_works2($bdd, $name, $description, $id, $id_region,$type_img) { // Ca c'est pour enregistrer la deuxieme photo
 if ($type_img != 3) {                       // met un argument qui est la derniere id ppour enregistrer les info de photo ou tu veux
    $req = $bdd->prepare('INSERT INTO works(work_name, work_description,user_id,id_region,img_type2) 
        VALUES(:name, :description, :user_id,:id_region,:img_type2)'); // tu lui specifie ou tu veux enregistrer avec le where ( c'est la ou ca bug )
    $req->execute(array(
        'name' => $name,
        'description' => $description,
        'user_id' => $id,
        'id_region' => $id_region,
        'img_type2' => $type_img
    ));
}else {
     $req = $bdd->prepare('INSERT INTO works(work_name, work_description,user_id,id_region) 
        VALUES(:name, :description, :user_id,:id_region) WHERE id_work = 70');
    $req->execute(array(
        'name' => $name,
        'description' => $description,
        'user_id' => $id,
        'id_region' => $id_region
    ));
    
    
}}


function model_create_worksimg2($bdd, $type_img,$last_id)
{ 
      $bdd->query("UPDATE works
            SET      img_type2 = '$type_img'
                    WHERE id_work = '$last_id'    ");
    
    
}
function count_work($bdd) {
    $req = $bdd->query('SELECT id_work FROM works');
    $count = $req->rowCount();
    return $count;
}

function select_id_works($bdd, $auteur) {

    $results = $bdd->query('  SELECT id_user FROM users
        WHERE user_name = "' . $auteur . '"
    
     ');

    return $results;
}

function select_last_id($bdd) {
    $results = $bdd->query('  SELECT id_work
FROM works 
ORDER BY id_work DESC 
LIMIT 0,1
    
     ');

    return $results;
}

function select_Allname_user($bdd) {

    $results = $bdd->query('  SELECT user_name FROM users
    
     ');

    return $results;
}
function check_exist($bdd,$id)
{
      $results = $bdd->query('  SELECT id_work FROM users
          WHERE id_work = '.$id.'
    
     ');
}
?>
